package com.h2cloud.redisTest;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.Jedis;

import java.util.Set;

/**
 * @Package: com.h2cloud.redisTest
 * @ClassName: TestZSet
 * @Author: h2cloud
 * @CreateTime: 2021/4/17 8:53 下午
 * @Description:
 */
public class TestZSet {
    private Jedis jedis;

    @Before
    public void before() {
        this.jedis = new Jedis("127.0.0.1", 6379);
    }

    @After
    public void after() {
        jedis.close();
    }


    //测试ZSET相关
    @Test
    public void testZset() {

        //zadd
        jedis.zadd("ZsetNames", 10, "张三");
        jedis.zadd("ZsetNames", 20, "王五");
        jedis.zadd("ZsetNames", 110, "李四");

        //zrange
        Set<String> zsetNames = jedis.zrange("ZsetNames", 0, -1);
        for (String name : zsetNames) {
            System.out.println(name);
        }

        //zcard
        Long nums = jedis.zcard("ZsetNames");
        System.out.println("个数：" + nums);

        //zrangeByScore
        jedis.zrangeByScore("ZsetNames", 0, 100, 0, 5);

        //..

    }

}

